package com.bynk.bynk_demo.service.impl;

import com.bynk.bynk_demo.dao.BookMapper;
import com.bynk.bynk_demo.dto.BookDto;
import com.bynk.bynk_demo.model.Book;
import com.bynk.bynk_demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;
    @Override
    public List<BookDto> getAllBook() {

        List<Book> books = bookMapper.selectList(null);

        List<BookDto> bookDtos = new ArrayList<>();

        for (Book book : books) {
            BookDto bookDto = new BookDto();

            // 从Book设置属性到BookDto
            bookDto.setBookId(book.getBookId().toString());
            bookDto.setBookName(book.getBookName());
            bookDto.setBookAuthor(book.getBookAuthor());

            // 根据需要添加更多的属性赋值

            // 将创建的BookDto添加到列表中
            bookDtos.add(bookDto);
        }

        return bookDtos;
    }
}
